package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.query.SystemDictionaryItemQuery;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.service.ISystemDictionaryService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/systemDictionaryItem")
public class SystemDictionaryItemController {
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    //注入属性,查询字典目录
    @Autowired
    private ISystemDictionaryService systemDictionaryService;

    @RequestMapping("/list")
    @RequiresPermissions(value = {"systemDictionaryItem:list","部门列表"}, logical=Logical.OR)//必须要有指定的权限才能访问该方法,所以之前的注解可以删了
    public String list(Model model, @ModelAttribute("qo") SystemDictionaryItemQuery qo) {//创建qo对象
        PageInfo pageInfo = systemDictionaryItemService.query(qo);

        model.addAttribute("result", pageInfo);
        //查询电邮所有字典的目录
        model.addAttribute("systemDictionarys",systemDictionaryService.listAll());

        return "systemDictionaryItem/list";
    }


    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(SystemDictionaryItem systemDictionaryItem) {

            if (systemDictionaryItem.getId() == null) {
                systemDictionaryItemService.save(systemDictionaryItem);
            } else {
                systemDictionaryItemService.update(systemDictionaryItem);
            }
            return new JsonResult();

    }


}
